/**
 * <b>项目名：</b>hclv-web<br/>
 * <b>包名：</b>com.flea.hclv.controller<br/>
 * <b>文件名：</b>HPayMentInfoController.java<br/>
 * <b>版本信息：</b>1.0<br/>
 * <b>日期：</b>2018年11月10日 下午5:36:08<br/>
 * <b>COPYRIGHT 2010-2012 ALL RIGHTS RESERVED 虫子科技</b>-版权所有<br/>
 */
package com.flea.hclv.controller;

import com.flea.hclv.model.entity.HVisitorPayItem;
import com.flea.hclv.model.entity.HVisitorRebackPaymentRecoder;
import com.flea.hclv.service.HVisitorPayItemService;
import com.flea.hclv.service.HVisitorRebackPaymentRecoderService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.bean.FleaPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description 游客支付信息，退款信息，分期还款信息
 * @createTime 2018年11月10日 下午5:36:08
 * @modifyTime
 * @author myflea@163.com
 * @version 1.0
 */
@Controller
@RequestMapping("/flea/hclv/visitor/visitorPay")
public class HVisitorPayMentInfoController {

    private Logger logger = LoggerFactory.getLogger(HVisitorPayMentInfoController.class);

    @Autowired
    private HVisitorPayItemService visitorPayItemService;
    @Autowired
    private HVisitorRebackPaymentRecoderService visitorRebackPaymentRecoderService;

    /**
     *
     * @description 游客支付e
     * @methodName addPayMent
     * @param
     * @returnType ServerResponse<HVisitorPayInfo>
     * @throw
     */
    @ResponseBody
    @RequestMapping("/addPayment")
    public ServerResponse<HVisitorPayItem> addPayMent(HttpServletRequest request, @RequestParam("model") String model) {
        ServerResponse<HVisitorPayItem> result = null;
        logger.info("添加游客支付记录，传入json:{}",model);
        try {
            result = visitorPayItemService.addPayItem(request, model);
        } catch (Exception e) {
            logger.error("添加游客支付记录异常",e.getMessage());
            e.printStackTrace();
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
        //1、支付项list
        //2、订单信息需要返回，或者订单号
        return result;

    }

    /**
     * 退款记录查询表
     * @description 只可以查询自己机构退款记录表
     * @methodName getRebackRecoder
     * @param
     * @returnType ServerResponse<HVisitorPayItem>
     * @throw
     */
    @ResponseBody
    @RequestMapping("/listRebackRecoder")
    public ServerResponse<FleaPage<HVisitorRebackPaymentRecoder>> getRebackRecoder(HttpServletRequest request, FleaPage<HVisitorRebackPaymentRecoder> paging) {
        //根据model：orderNo进行查询
        String orderNo = request.getParameter("model");
        ServerResponse<FleaPage<HVisitorRebackPaymentRecoder>> result = visitorRebackPaymentRecoderService.getRebackRecoderByOrgIdForPaging(request, paging.getCurPage(), paging.getPageSize(), orderNo);
        return result;
    }

  /**
   * 添加游客退款记录，model有两个对象 orderNo，rebackRecoder
   * @param request
   * @param model
   * @return
   */
  @ResponseBody
  @RequestMapping("/addRebackRecoder")
    public ServerResponse addRebackRecoder(HttpServletRequest request,String model){
    try {
      ServerResponse result =  visitorRebackPaymentRecoderService.addRebackRecoder(model,request);
      return result;
    } catch (Exception e) {
      return ServerResponse.createByErrorMessage(e.getMessage());
    }
  }
  /**
   * 添加游客退款记录查询，根据orderNo，
   * @param request
   * @return
   */
  @ResponseBody
  @RequestMapping("/getRebackRecoderByOrder")
    public ServerResponse findRebackRecoderByOrderNo(HttpServletRequest request,FleaPage paging){
    String model = request.getParameter("orderNo");
    try {
      ServerResponse result =  visitorRebackPaymentRecoderService.findRebackRecoderByOrderNo(model,request,paging.getCurPage(),paging.getPageSize());
      return result;
    } catch (Exception e) {
      return ServerResponse.createByErrorMessage(e.getMessage());
    }
  }

    @ResponseBody
    @RequestMapping("/listPayInfo")
    public ServerResponse<List<HVisitorPayItem>> getPayRecoder(HttpServletRequest request) {
        //根据model：orderNo进行查询
        String orderNo = request.getParameter("model");
        ServerResponse<List<HVisitorPayItem>> result = null;
        try {
            result = visitorPayItemService.getPayListByOrderNo(orderNo);
        } catch (Exception e) {
            return ServerResponse.createByErrorMessage(e.getMessage());
        }

        return result;

    }


}
